<template>
  <div class="wrap">
    <packet-goods-form
        :form="goodsData"
        :type="'create'"
        @back="back"
        @submit="submit"
    ></packet-goods-form>
  </div>
</template>

<script>
import PacketGoodsForm from "@/views/packetGoods/components/PacketGoodsForm.vue";
import {savePacketGoodsData} from "@/api/packetGoods";

export default {
  components: {
    PacketGoodsForm,
  },
  data() {
    return {
      goodsData: {
        title: '',
        sku: '',
        image: '',
        length: 0,
        width: 0,
        height: 0,
        weight: 0,
        goodsNumInBox: 0,
        packageMaterialId: 0,
        goodsValue: 0,
        isCombination: 0,
        goodsNameZh: '',
        goodsName: '',
        material: '', // 材质
        application: '', // 用途
        brand: '', // 品牌
        packet_weight: 0,
        packet_length: 0,
        packet_width: 0,
        packet_height: 0,
        goodsType: '',
        goodsAttr: [],
      },
    }
  },
  created() {

  },

  methods: {

    back() {
      this.$router.push({name: 'stockList'});
    },
    submit(goodsData) {
      savePacketGoodsData(goodsData)
          .then(res => {
            if (res.error === 0) {
              this.$successMessage(this.$t('packet.保存成功'))
              this.$router.push({name: 'stockList'})
            } else {
              this.$errorMessage(res.message)
            }
          });
    },
  }
}
</script>

<style scoped lang="less">
.wrap{
  padding: 30px;
}
</style>
